package com.whut.coc.application.tools;

import com.whut.coc.adapter.client.COCClient;
import com.whut.coc.adapter.dto.PlayerDTO;
import com.whut.coc.domain.service.UserTagDomainService;
import dev.langchain4j.agent.tool.P;
import dev.langchain4j.agent.tool.Tool;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description:
 * @Author: Zonghe Wang
 * @Date: 2025/6/22 17:10
 */
@RequiredArgsConstructor
@Component
public class COCTool {

    private final UserTagDomainService userTagDomainService;

    private final COCClient cocClient;

    /**
     * 工具方法：添加用户标签
     * @param uid 用户id
     * @param tag 标签
     */
    @Tool("为用户添加村庄标签")
    public void addUserTag(
            @P(value = "用户的id", required = true) Long uid,
            @P(value = "用户部落冲突村庄的标签或者叫做用户部落冲突村庄的标签的编号，格式总长度为10位，为#开头后面9位大写字母或数字", required = true) String tag
    ) {
        boolean saved = userTagDomainService.save(uid, tag);
        if (!saved) {
            throw new RuntimeException("添加用户标签失败");
        }
    }

    /**
     * 查询用户村庄
     * @param uid
     * @return
     */
    @Tool(name = "查询用户部落冲突村庄的标签或者用户部落冲突村庄的标签的编号")
    public List<String> queryUserTag(
        @P(value = "用户的id" , required = true) Long uid
    ) {
        return userTagDomainService.queryByUid(uid);
    }

    @Tool(name = "根据用户部落冲突村庄的标签查询用户信息")
    public PlayerDTO queryPlayerInfo(
        @P(value = "用户的标签" , required = true) String tag
    ) {
        return cocClient.getPlayerInfo(tag);
    }


}
